{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.6"
    },
    "pycharm": {
      "stem_cell": {
        "cell_type": "raw",
        "source": [],
        "metadata": {
          "collapsed": false
        }
      }
    },
    "colab": {
      "name": "Fake_News.ipynb",
      "provenance": [],
      "collapsed_sections": []
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "rFCzxMzfG2Jh",
        "colab_type": "text"
      },
      "source": [
        "#Fake News\n",
        "\n",
        "Copyright 2020, Denis Rothman\n",
        "\n",
        "## Notebook resources:\n",
        "\n",
        "[Hugging Face](https://huggingface.co)\n",
        "\n",
        "[The Allen Institute for AI](https://allennlp.org/)<br>\n",
        "Some of Allen NLP resources come from Hugging Face\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "_UlmKCHMttiY",
        "colab_type": "text"
      },
      "source": [
        "## Fake News from an emotional perspective \n",
        "\n",
        "Allen NLP Sentiment Analysis with RoBERTa-large \n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "TssYtycqPQSW",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!pip install allennlp==1.0.0 allennlp-models==1.0.0"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "4-nbsdFAQyVj",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!echo '{\"sentence\":\"Climate change is bogus. It’s a plot by the liberals to take the economy down.\"}' | \\\n",
        "allennlp predict https://storage.googleapis.com/allennlp-public-models/sst-roberta-large-2020.06.08.tar.gz -"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "id": "jFgnbGsEwXUe",
        "colab": {}
      },
      "source": [
        "!echo '{\"sentence\":\"I am a Republican and think that climate change consciousness is a great thing!\"}' | \\\n",
        "allennlp predict https://storage.googleapis.com/allennlp-public-models/sst-roberta-large-2020.06.08.tar.gz -"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "5TWl4dpzbGe6",
        "colab_type": "text"
      },
      "source": [
        "## GUN CONTROL"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "id": "pDX7NjFVa31H",
        "colab": {}
      },
      "source": [
        "!echo '{\"sentence\":\"I have had rifles and guns for years and never had a problem. I raised my kids right so they have guns too and never hurt anything except rabbits.\"}' | \\\n",
        "allennlp predict https://storage.googleapis.com/allennlp-public-models/sst-roberta-large-2020.06.08.tar.gz -"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "id": "PpdecpJPfTl6",
        "colab": {}
      },
      "source": [
        "!echo '{\"sentence\":\"I have heard gunshots all my life in my neighborhood, have lost many friends, and am afraid to go out at night.\"}' | \\\n",
        "allennlp predict https://storage.googleapis.com/allennlp-public-models/sst-roberta-large-2020.06.08.tar.gz -"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "pycharm": {
          "name": "#%% code\n"
        },
        "id": "4maAknWNrl_N",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!pip install -q transformers"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "pycharm": {
          "is_executing": false,
          "name": "#%% code \n"
        },
        "id": "uKaqzCh6rl_V",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "from transformers import pipeline\n",
        "from transformers import AutoTokenizer, AutoModelForSequenceClassification,AutoModel"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "6bWOwVgIh9Ai",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "nlp_token_class = pipeline('ner')\n",
        "nlp_token_class('I have had rifles and guns for years and never had a problem. I raised my kids right so they have guns too and never hurt anything except rabbits.')"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "id": "69Az4owA2UQv",
        "colab": {}
      },
      "source": [
        "nlp_token_class = pipeline('ner')\n",
        "nlp_token_class('I have had rifles and guns for years and never had a problem. I raised my kids right so they have guns too and never hurt anything except rabbits.')"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "id": "VmJw_cAmkI43",
        "colab": {}
      },
      "source": [
        "nlp_token_class.model.config"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "IE-TRXfppsKJ",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!echo '{\"sentence\": \"I have heard gunshots all my life in my neighborhood, have lost many friends, and am afraid to go out at night.\"}' | \\\n",
        "allennlp predict https://storage.googleapis.com/allennlp-public-models/bert-base-srl-2020.03.24.tar.gz -"
      ],
      "execution_count": null,
      "outputs": []
    }
  ]
}